  /**
实现 pow(x, n) ，即计算 x 的 n 次幂函数（即，x⁴

 Related Topics 递归 数学 👍 828 👎 0

*/

package medium._0050.pck.s1;
public class PowxN{
  public static void main(String[] args) {
      Solution solution = new PowxN().new Solution();
      final double pow = solution.myPow(2, 10);
      System.out.println("pow = " + pow);
  }
  //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
      /*
       * 使用暴力法；时间复杂度不符合题目
       */
      public double myPow(double x, int n) {
          double res = 1;
          final int abs = Math.abs(n);
          for (int i = 0; i < abs; i++) {
              res *= x;
          }
          if (n < 0) {
              res = 1 / res;
          }

          return res;

      }
  }
//leetcode submit region end(Prohibit modification and deletion)

}